<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
require_once PHPEXCEL_ROOT . "PHPExcel/Shared/trend/linearBestFitClass.php";
require_once PHPEXCEL_ROOT . "PHPExcel/Shared/trend/logarithmicBestFitClass.php";
require_once PHPEXCEL_ROOT . "PHPExcel/Shared/trend/exponentialBestFitClass.php";
require_once PHPEXCEL_ROOT . "PHPExcel/Shared/trend/powerBestFitClass.php";
require_once PHPEXCEL_ROOT . "PHPExcel/Shared/trend/polynomialBestFitClass.php";
class trendClass
{
    private static $trendCache = [];
    private static $trendTypes = ["Linear", "Logarithmic", "Exponential", "Power"];
    private static $trendTypePolynomialOrders = ["Polynomial_2", "Polynomial_3", "Polynomial_4", "Polynomial_5", "Polynomial_6"];
    const TREND_LINEAR = "Linear";
    const TREND_LOGARITHMIC = "Logarithmic";
    const TREND_EXPONENTIAL = "Exponential";
    const TREND_POWER = "Power";
    const TREND_POLYNOMIAL_2 = "Polynomial_2";
    const TREND_POLYNOMIAL_3 = "Polynomial_3";
    const TREND_POLYNOMIAL_4 = "Polynomial_4";
    const TREND_POLYNOMIAL_5 = "Polynomial_5";
    const TREND_POLYNOMIAL_6 = "Polynomial_6";
    const TREND_BEST_FIT = "Bestfit";
    const TREND_BEST_FIT_NO_POLY = "Bestfit_no_Polynomials";
    public static function calculate($trendType = self::TREND_BEST_FIT, $yValues, $xValues = [], $const = true)
    {
        $nY = count($yValues);
        $nX = count($xValues);
        if($nX == 0) {
            $xValues = range(1, $nY);
            $nX = $nY;
        } elseif($nY != $nX) {
            trigger_error("trend(): Number of elements in coordinate arrays do not match.", 256);
        }
        $key = md5($trendType . $const . serialize($yValues) . serialize($xValues));
        switch ($trendType) {
            case "Linear":
            case "Logarithmic":
            case "Exponential":
            case "Power":
                if(!isset(self::$trendCache[$key])) {
                    $className = "PHPExcel_" . $trendType . "_Best_Fit";
                    self::$trendCache[$key] = new $className($yValues, $xValues, $const);
                }
                return self::$trendCache[$key];
                break;
            case "Polynomial_2":
            case "Polynomial_3":
            case "Polynomial_4":
            case "Polynomial_5":
            case "Polynomial_6":
                if(!isset(self::$trendCache[$key])) {
                    $order = substr($trendType, -1);
                    self::$trendCache[$key] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
                }
                return self::$trendCache[$key];
                break;
            case "Bestfit":
            case "Bestfit_no_Polynomials":
                foreach (self::$trendTypes as $trendMethod) {
                    $className = "PHPExcel_" . $trendMethod . "BestFit";
                    $bestFit[$trendMethod] = new $className($yValues, $xValues, $const);
                    $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
                }
                if($trendType != "Bestfit_no_Polynomials") {
                    foreach (self::$trendTypePolynomialOrders as $trendMethod) {
                        $order = substr($trendMethod, -1);
                        $bestFit[$trendMethod] = new PHPExcel_Polynomial_Best_Fit($order, $yValues, $xValues, $const);
                        if($bestFit[$trendMethod]->getError()) {
                            unset($bestFit[$trendMethod]);
                        } else {
                            $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
                        }
                    }
                }
                arsort($bestFitValue);
                $bestFitType = key($bestFitValue);
                return $bestFit[$bestFitType];
                break;
            default:
                return false;
        }
    }
}

?>